package domfarr.tapestry.pages;

import java.util.Collection;

import org.apache.tapestry5.ValueEncoder;

public class GreetingEncoder implements ValueEncoder<Greeting> {

	private Collection<Greeting> list;

	public GreetingEncoder(Collection<Greeting> list) {
		this.list = list;
	}

	public String toClient(Greeting value) {
		return value.getGreeting();
	}

	public Greeting toValue(String clientValue) {
		for (Greeting greeting : list) {
			if (greeting.getGreeting().equals(clientValue)) {
				return greeting;
			}
		}
		return null;
	}

}
